package com.cattsoft.util.common.service.hibernateimpl;

import java.io.Serializable;
import java.util.List;
import com.cattsoft.util.common.dao.IGenericDao;
import com.cattsoft.util.common.exception.OssApplicationException;
import com.cattsoft.util.common.service.IGenericService;

public class GenericHibernateServiceImpl<T, ID extends Serializable> implements
		IGenericService<T, ID> {
	private IGenericDao genericDao;

	public IGenericDao getGenericDao() {
		return genericDao;
	}

	public void setGenericDao(IGenericDao genericDao) {
		this.genericDao = genericDao;
	}

	public T getByID(Class<T> obj, ID id) throws OssApplicationException {
		return (T) genericDao.findByPK(obj, id);
	}

	public List<T> getByHql(String hql, Object[] queryArgs)
			throws OssApplicationException {
		return genericDao.findByHql(hql, queryArgs);
	}

	public List<T> getByHql(String hql, Object queryArg)
			throws OssApplicationException {
		return genericDao.findByHql(hql, queryArg);
	}

	public List<T> getByHql(String hql) throws OssApplicationException {
		return genericDao.findByHql(hql);
	}

	public List<T> getAll(Class<T> obj) throws OssApplicationException {
		return genericDao.findAll(obj);
	}

	public Object SaveData(T obj) throws OssApplicationException {
		if (genericDao.save(obj)) {
			return obj;
		} else {
			return null;
		}
	}

	public boolean DeleteData(T obj) throws OssApplicationException {
		return genericDao.delete(obj);
	}

	public boolean DeleteByIDs(Class<T> obj, ID[] id)
			throws OssApplicationException {
		return genericDao.deleteByPKs(obj, id);
	}

	@SuppressWarnings("unchecked")
	public boolean DeleteByID(Class<T> obj, ID id)
			throws OssApplicationException {
		return genericDao.deleteByPK(obj, id);
	}

	public void updataByHql(String hql, Object updataArg) throws OssApplicationException {
		genericDao.updataAll(hql, updataArg);
		
	}
	public void updataByHql(Object hql) throws OssApplicationException {
		genericDao.updataAll(hql);
		
	}

	public void DeleteAll(List list) throws OssApplicationException {
		genericDao.deleteAll(list);
	}
}
